package com.wx.core.vo;

import java.io.Serializable;
import java.util.List;

import com.wx.entity.SysMenu;
import com.wx.util.StringUtils;

public class SysMenuSet extends PurviewSet<SysMenu>  implements Serializable {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 5872329618944377145L;

	public SysMenuSet(List<SysMenu> list){
		super(list);
	}
	/**
	 * 
	 * @param url
	 * @return
	 */
	public boolean contains(String permissions) {
		permissions = StringUtils.isNull(permissions);
		if (!hasList() || permissions == null || permissions.isEmpty()) {
			return false;
		}
		
		for (SysMenu p : getPurviewList()) {
			if (StringUtils.isNull(p.getPermissions()).equals(permissions)) {
				return true;
			}
		}
		return false;
	}
	
	@Override
	public int compares(SysMenu model1, SysMenu model2) {
		//过滤相同菜单
		if(model1.getId()!=null &&  model2.getId()!=null && (model1.getId().intValue() == model2.getId().intValue() )){
			return 0;
		}
		if(model1.getMenuOrder()==null || model2.getMenuOrder()==null ){
			return -1;
		}
		//添加排序
		int result = (model1.getMenuOrder().intValue()>model2.getMenuOrder().intValue()) ?  -1:1 ;
        return result;
	}

	@Override
	public boolean isTrunk(SysMenu trunk) {
		return trunk.getParentId()==0;
	}

	@Override
	public boolean isLeaf(SysMenu trunk, SysMenu leaf) {
		if(trunk.getId()!=null && leaf.getParentId()!=null && trunk.getId().intValue() == leaf.getParentId().intValue() ){
			return true;
		}else{
			return false;
		}
	}
}
